﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using EsuApiLib;
using EsuApiLib.Rest;

namespace AtmosClientWinForms
{
    public partial class AtmosSettingsForm : Form
    {
        private EsuApi m_esuObj = null;
        private String m_atmosServer = null;
        private int m_portNum = 80;
        private String m_tokenID = null;
        private String m_sharedSecret = null;

        public AtmosSettingsForm(EsuApi esuObj)
        {
            InitializeComponent();
            m_esuObj = esuObj;
        }

        public EsuApi EsuObject
        {
            get { return m_esuObj; }
        }

        private void m_acceptButton_Click(object sender, EventArgs e)
        {
            int count = 0;

            if (!String.IsNullOrEmpty(m_atmosServerBox.Text))
            {
                m_atmosServer = m_atmosServerBox.Text.Trim();
                count++;
            }
            if (!String.IsNullOrEmpty(m_PortNumBox.Text))
            {
                String sPort = m_PortNumBox.Text.Trim();
                if (!Int32.TryParse(sPort, out m_portNum))
                {
                    MessageBox.Show("This value must be an integer port number.", "Atmos Client");
                }
                else
                {
                    count++;
                }
            }
            if (!String.IsNullOrEmpty(m_tokenIDBox.Text))
            {
                m_tokenID = m_tokenIDBox.Text.Trim();
                count++;
            }
            if (!String.IsNullOrEmpty(m_sharedSecretBox.Text))
            {
                m_sharedSecret = m_sharedSecretBox.Text.Trim();
                count++;
            }

            if (count == 4)
            {
                m_esuObj = new EsuRestApi(m_atmosServer, m_portNum, m_tokenID, m_sharedSecret);
                Close();
            }

        }

    }
}
